package com.luoxiang.socialandroid.adapter;

import static com.luoxiang.lib_common.common.Constants.MmkvConst.DOMAIN;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.luoxiang.socialandroid.R;
import com.luoxiang.socialandroid.app.MyAppliaction;
import com.luoxiang.socialandroid.bean.WithdrawLog;

import java.util.ArrayList;
import java.util.List;

public class JifenAdapter extends RecyclerView.Adapter<JifenAdapter.ViewHolder> {
    private List<WithdrawLog> list = new ArrayList<>();

    public void setData(List<WithdrawLog> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_tixian, parent, false);
        JifenAdapter.ViewHolder holder = new JifenAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Glide.with(MyAppliaction.getContext())
                .load(DOMAIN + list.get(position).getIcon())
                .apply(RequestOptions.bitmapTransform(new CircleCrop()))//圆角半径
                .into(holder.img_paymodel);
        holder.enter_number.setText(list.get(position).getDesc());
        holder.tv_date.setText(list.get(position).getCreateTime());
        holder.add_ppbi.setText("-" + list.get(position).getAmount() + holder.add_ppbi.getContext().getString(R.string.mi_yuan));
        switch (list.get(position).getStatus()) {
            case 0:
                holder.tv_setaccept.setText("申请中");
                break;
            case 1:
                holder.tv_setaccept.setText("已通过");
                break;
            case 2:
                holder.tv_setaccept.setText("已驳回");
                break;
        }
    }

    @Override
    public int getItemCount() {
        if (list != null) {
            return list.size();

        } else {
            return 0;
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView img_paymodel;
        TextView enter_number, tv_date, add_ppbi, tv_setaccept;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            img_paymodel = itemView.findViewById(R.id.img_paymodel);
            enter_number = itemView.findViewById(R.id.enter_number);
            tv_date = itemView.findViewById(R.id.tv_date);
            tv_setaccept = itemView.findViewById(R.id.tv_setaccept);
            add_ppbi = itemView.findViewById(R.id.add_ppbi);
        }
    }
}
